package com.qdsgjsfk.vision.ui;

import android.widget.EditText;
import android.widget.Toast;

import com.qdsgjsfk.vision.R;
import com.qdsgjsfk.vision.util.UtilString;
import com.rest.business.RestProxy;
import com.rest.response.BaseResponse;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import com.qdsgjsfk.vision.base.BaseActivity;
import com.qdsgjsfk.vision.util.NetUtil;

/**
 *修改密码
 * @time 2021/3/17 14:04
 */

public class PasswordActivity extends BaseActivity {

    @BindView(R.id.edt_password)
    EditText edt_password;

    @BindView(R.id.edt_new_password)
    EditText edt_new_password;
    @BindView(R.id.edt_new_check_password)
    EditText edt_new_check_password;

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_password;
    }


    @OnClick(R.id.btn_confirm)
    void btn_confirm() {
        updateUserInfo();
    }

    private void updateUserInfo() {
        if (edt_new_password.getText().toString().trim().length() < 8) {
            Toast.makeText( PasswordActivity.this, "请输入至少8位数密码", Toast.LENGTH_SHORT ).show();
            return;
        }

        if (!UtilString.isPasswordNo( edt_new_password.getText().toString().trim() )) {
            Toast.makeText( PasswordActivity.this, "请按照要求输入规则的密码", Toast.LENGTH_SHORT ).show();
            return;
        }
        if (!edt_new_password.getText().toString().trim().equals( edt_new_check_password.getText().toString().trim() )) {
            Toast.makeText( PasswordActivity.this, "两次输入的新密码不一样", Toast.LENGTH_SHORT ).show();
            return;
        }

        RestProxy.getInstance().updatePassword( edt_password.getText().toString().trim(), edt_new_password.getText().toString().trim(), new Observer<BaseResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(BaseResponse baseResponse) {
                finish();
            }

            @Override
            public void onError(Throwable e) {
                NetUtil.onError( e, PasswordActivity.this );
            }

            @Override
            public void onComplete() {


            }
        } );
    }
}
